<template>
    <div id="cc">
        <div style="position: sticky;top:0;z-index: 9999;background: #fff;">
            <div style="display: flex;flex-direction: row;height: 40px;">
                <div
                        style="display: flex;justify-content: center;align-items: center;width: 25vw;
                        font-family: PingFangSC-Regular;font-size: 14px;"
                        :style="{borderBottom:activeStep==index?'2px solid #454592':'1px solid #ddd',color:activeStep==index?'#454592':'#333'}"
                        v-for="(item,index) in ['基本','疾病','合病症','治疗']"
                        @click="privilegeHeadClick('anchor-'+index)">
                    <span>
                      {{item}}
                    </span>
                </div>
            </div>
        </div>
        <div class="wrapper" id="section">
            <!--基本信息-->
            <div id="anchor-0" class="privilege-wrap">
                <!--标题-->
                <div class="title">
                    <div class="title_block"></div>
                    <div class="title_text">
                        基本信息
                    </div>
                </div>
                <!--field-->
                <div class="field_item">
                    <div class="field_title">
                        年龄
                    </div>
                    <div>
                        <Field v-model="form.tabBasic.B02" type="number"/>
                    </div>
                </div>
                <div class="field_item">
                    <div class="field_title">
                        体重(kg)
                    </div>
                    <div>
                        <Field v-model="form.tabBasic.B04" type="number"/>
                    </div>
                </div>
                <div class="field_item">
                    <div class="field_title">
                        身高(cm)
                    </div>
                    <div>
                        <Field v-model="form.tabBasic.B07" type="number"/>
                    </div>
                </div>
                <div class="field_item">
                    <div class="field_title">
                        BMI(kg/m2)
                    </div>
                    <div>
                        <Field v-model="form.tabBasic.B05" type="number"/>
                    </div>
                </div>
                <div class="field_item">
                    <div class="field_title">
                        性别
                    </div>
                    <div>
                        <Cell is-link :title="form.tabBasic.B03" @click="genderShow=true"/>
                    </div>
                </div>
                <div class="field_item">
                    <div class="field_title">
                        地点
                    </div>
                    <div>
                        <Cell is-link :title="form.tabBasic.B01" @click="locationShow=true"/>
                    </div>
                </div>
                <div class="field_item">
                    <div class="field_title">
                        病程（年）
                    </div>
                    <div>
                        <Cell is-link :title="form.tabBasic.B06" @click="diseaseyearShow=true"/>
                    </div>
                </div>
                <Overlay :show="genderShow">
                    <RadioList :fullList="genderOptions" :checked="form.tabBasic.B03" @confirm="genderConfirm"
                               @cancel="genderShow=false"/>
                </Overlay>
                <Overlay :show="locationShow">
                    <RadioList :fullList="locationOptions" :checked="form.tabBasic.B01" @confirm="locationConfirm"
                               @cancel="locationShow=false"/>
                </Overlay>
                <Overlay :show="diseaseyearShow">
                    <RadioList :fullList="diseaseyearOptions" :checked="form.tabBasic.B06" @confirm="diseaseyearConfirm"
                               @cancel="diseaseyearShow=false"/>
                </Overlay>
            </div>
            <!--基本信息-->
            <!--疾病信息-->
            <div class="mt20 privilege-wrap" id="anchor-1">
                <!--标题-->
                <div class="title">
                    <div class="title_block"></div>
                    <div class="title_text">
                        疾病信息
                    </div>
                </div>
                <!--field-->
                <div class="field_item">
                    <div class="field_title">
                        空腹血糖（mmol/L）
                    </div>
                    <div>
                        <Field v-model="form.tabDisease.D01" type="number"/>
                    </div>
                </div>
                <div class="field_item">
                    <div class="field_title">
                        餐后血糖（mmol/L）
                    </div>
                    <div>
                        <Field v-model="form.tabDisease.D02" type="number"/>
                    </div>
                </div>
                <div class="field_item">
                    <div class="field_title">
                        糖化血红蛋白（%）
                    </div>
                    <div>
                        <Field v-model="form.tabDisease.D03" type="number"/>
                    </div>
                </div>
            </div>
            <!--疾病信息-->
            <!--合并症信息-->
            <div class="mt20 privilege-wrap" id="anchor-2">
                <!--标题-->
                <div class="title">
                    <div class="title_block"></div>
                    <div class="title_text">
                        合并症信息
                    </div>
                </div>
                <!--field-->
                <div class="field_item">
                    <div class="field_title">
                        伴发疾病及既往史（可多选）
                    </div>
                    <div>
                        <Cell is-link :title="form.tabComplication.C15.join(',')" @click="diseaseHistoryShow=true"/>
                    </div>
                </div>
                <div v-if="form.tabComplication.C15.includes('急性冠脉综合征')">
                    <div class="title_sub">
                        急性冠状脉综合症
                    </div>
                    <div class="field_item">
                        <div class="field_title">
                            目前状态
                        </div>
                        <div>
                            <Cell is-link :title="form.tabComplication.C07" @click="currentStatusShow=true"/>
                        </div>
                    </div>
                    <div class="field_item" v-if="form.tabComplication.C07=='急性发作'">
                        <div class="field_item">
                            <div class="field_title">
                                急性期治疗方案
                            </div>
                            <div>
                                <Cell is-link :title="form.tabComplication.C09" @click="acuteplanShow=true"/>
                            </div>
                        </div>
                        <div class="field_item">
                            <div class="field_title">
                                心电图（可多选）
                            </div>
                            <div>
                                <Cell is-link :title="form.tabComplication.C08.join(',')" @click="ecgShow=true"/>
                            </div>
                        </div>
                    </div>
                </div>
                <div v-if="form.tabComplication.C15.includes('高血压')">
                    <div class="title_sub">
                        高血压
                    </div>
                    <div class="field_item">
                        <div class="field_title">
                            舒张压(mmHg)
                        </div>
                        <div>
                            <Field v-model="form.tabComplication.C14" type="number"/>
                        </div>
                    </div>
                    <div class="field_item">
                        <div class="field_title">
                            收缩压(mmHg)
                        </div>
                        <div>
                            <Field v-model="form.tabComplication.C13" type="number"/>
                        </div>
                    </div>
                </div>
                <Overlay :show="diseaseHistoryShow">
                    <CheckboxList :fullList="diseaseHistoryOptions" :checked="form.tabComplication.C15"
                                  @confirm="diseaseHistoryconfirm" @cancel="diseaseHistoryShow = false"/>
                </Overlay>
                <Overlay :show="currentStatusShow">
                    <RadioList :fullList="currentStatusOptions" :checked="form.tabComplication.C07"
                               @confirm="currentStatusConfirm"
                               @cancel="currentStatusShow=false"/>
                </Overlay>
                <Overlay :show="acuteplanShow">
                    <RadioList :fullList="acuteplanOptions" :checked="form.tabComplication.C09"
                               @confirm="acuteplanConfirm"
                               @cancel="acuteplanShow=false"/>
                </Overlay>
                <Overlay :show="ecgShow">
                    <CheckboxList :fullList="ecgOptions" :checked="form.tabComplication.C08"
                                  @confirm="ecgConfirm" @cancel="ecgShow = false"/>
                </Overlay>

            </div>
            <!--合并症信息-->
            <!--治疗信息-->
            <div class="mt20 privilege-wrap" id="anchor-3">
                <!--标题-->
                <div class="title">
                    <div class="title_block"></div>
                    <div class="title_text">
                        治疗信息
                    </div>
                </div>
                <!--field-->
                <div class="field_item" v-if="form.tabBasic.B06!='新诊断或小于半年'">
                    <div class="field_title">
                        上次治疗方案（可多选）
                    </div>
                    <div>
                        <Cell is-link :title="form.treatment.T09.join(',')" @click="lastplanShow=true"/>
                    </div>
                </div>
                <div class="field_item">
                    <div class="field_title">
                        当前方案（可多选）
                    </div>
                    <div>
                        <Cell is-link :title="form.treatment.T05.join(',')" @click="currentplanShow=true"/>
                    </div>
                </div>
                <div class="field_item">
                    <div class="field_title">
                        目前亚莫利剂量（mg）
                    </div>
                    <div>
                        <Field v-model="form.treatment.T06" type="number"/>
                    </div>
                </div>
                <div class="field_item">
                    <div class="field_title">
                        建议亚莫利用药时间（月）
                    </div>
                    <div>
                        <Cell is-link :title="form.treatment.T08"
                              @click="amaryl_recommand_timeShow=true"/>
                    </div>
                </div>
                <Overlay :show="lastplanShow">
                    <CheckboxList :fullList="lastplanOptions" :checked="form.treatment.T09"
                                  @confirm="lastplanConfirm" @cancel="lastplanShow = false"/>
                </Overlay>
                <Overlay :show="currentplanShow">
                    <CheckboxList :fullList="currentplanOptions" :checked="form.treatment.T05"
                                  @confirm="currentplanConfirm" @cancel="currentplanShow = false"/>
                </Overlay>
                <Overlay :show="amaryl_recommand_timeShow">
                    <RadioList :fullList="amaryl_recommand_timeOptions" :checked="form.treatment.T08"
                               @confirm="amaryl_recommand_timeConfirm"
                               @cancel="amaryl_recommand_timeShow=false"/>
                </Overlay>

            </div>
            <!--治疗信息-->
            <!--保存按钮-->
            <div class="submit">
                <div class="submit_btn" @click="save">
                    保存
                </div>
            </div>
            <div class="submit_btn2" @click="submit">
                提交
            </div>
        </div>
        <div>
            <img :src="cloud_img" style="width: 100%"/>
        </div>
    </div>

</template>

<script>
    import {Field, Cell, Popup, Picker, Toast, Overlay, Checkbox, CheckboxGroup, CellGroup} from 'vant';
    import cloud_img from '@assets/image/cloud.svg'
    import RadioList from "@components/snfRadioList/index";
    import CheckboxList from "@components/snfCheckboxList/index";

    const genderOptions = ['男', '女']
    const locationOptions = ['病房', '门诊']
    const diseaseyearOptions = ['新诊断或小于半年', '0.5-2（不包括2年）', '2-5（不包括5年）', '5-8（不包括8年）', '≥8']
    const diseaseHistoryOptions = ['高血压', '卒中史', '急性冠脉综合征', '血脂异常', '其他', '无']
    const currentStatusOptions = ['急性发作', '既往史']
    const acuteplanOptions = ['PCI', '非PCI']
    const ecgOptions = ['ST抬高', 'ST压低', 'T波倒置', '病理性Q波', '无明显变化']
    const lastplanOptions = ['口服降糖药单药', '口服降糖药联合（不包括胰岛素）', '胰岛素方案（包括联合口服药）', '其他', '未治疗']
    const currentplanOptions = ['亚莫利®', '其他口服降糖药', '胰岛素', '其他']
    const amaryl_recommand_timeOptions = ['<1', '1-3', '3-6', '6-12', '≥12']
    export default {
        name: "add",
        props: {
            scheduleId: String,
            tabActive: Number
        },
        components: {
            CheckboxList,
            RadioList,
            Field,
            Cell,
            Popup,
            Picker,
            Toast,
            Overlay,
            Checkbox,
            CheckboxGroup,
            CellGroup
        },
        data() {
            return {
                active: '',
                activeStep: '',
                form: {
                    finish: false,
                    callPlanId: this.scheduleId,
                    prodName: '亚莫利',
                    prodId: 'AMARYL',
                    tabBasic: {
                        B02: '',
                        B04: '',
                        B07: '',
                        B05: '',
                        B03: '',
                        B01: '',
                        B06: ''
                    },
                    tabDisease: {
                        D01: '',
                        D02: '',
                        D03: '',
                    },
                    tabComplication: {
                        C15: [],
                        C07: '',
                        C09: '',
                        C08: [],
                        C14: '',
                        C13: ''
                    },
                    treatment: {
                        T09: [],
                        T05: [],
                        T06: '',
                        T08: ''
                    }
                },
                genderShow: false,
                locationShow: false,
                diseaseyearShow: false,
                diseaseHistoryShow: false,
                currentStatusShow: false,
                acuteplanShow: false,
                ecgShow: false,
                lastplanShow: false,
                currentplanShow: false,
                amaryl_recommand_timeShow: false,
                genderOptions: genderOptions,
                locationOptions: locationOptions,
                diseaseyearOptions: diseaseyearOptions,
                diseaseHistoryOptions: diseaseHistoryOptions,
                currentStatusOptions: currentStatusOptions,
                acuteplanOptions: acuteplanOptions,
                ecgOptions: ecgOptions,
                lastplanOptions: lastplanOptions,
                currentplanOptions: currentplanOptions,
                amaryl_recommand_timeOptions: amaryl_recommand_timeOptions,
                cloud_img: cloud_img
            }
        },
        methods: {
            currentplanConfirm(value, index) {
                this.form.treatment.T05 = value
                this.currentplanShow = false
            },
            lastplanConfirm(value, index) {
                this.form.treatment.T09 = value
                this.lastplanShow = false
            },
            ecgConfirm(value, index) {
                this.form.tabComplication.C08 = value
                this.ecgShow = false
            },
            diseaseHistoryconfirm(value, index) {
                this.form.tabComplication.C15 = value
                this.diseaseHistoryShow = false
            },
            onScroll(e) {
                let scrollItems = document.querySelectorAll(".privilege-wrap");
                for (let i = scrollItems.length - 1; i >= 0; i--) {
                    // 判断滚动条滚动距离是否大于当前滚动项可滚动距离
                    let judge =
                        e.target.scrollTop >=
                        scrollItems[i].offsetTop - scrollItems[0].offsetTop;
                    if (judge) {
                        this.activeStep = i;
                        this.active = this.activeStep
                        break;
                    }
                }
            },
            privilegeHeadClick(anchor) {
                this.$nextTick(() => {
                    document.querySelector(`#${anchor}`).scrollIntoView({
                        behavior: "smooth", // 平滑过渡
                        block: "start" // 上边框与视窗顶部平齐。默认值
                    });
                });
            },
            amaryl_recommand_timeConfirm(value, index) {
                this.form.treatment.T08 = value
                this.amaryl_recommand_timeShow = false
            },
            acuteplanConfirm(value, index) {
                this.form.tabComplication.C09 = value
                this.acuteplanShow = false
            },
            currentStatusConfirm(value, index) {
                this.form.tabComplication.C07 = value
                this.currentStatusShow = false
            },
            diseaseyearConfirm(value, index) {
                this.form.tabBasic.B06 = value
                this.diseaseyearShow = false
            },
            genderConfirm(value, index) {
                this.form.tabBasic.B03 = value
                this.genderShow = false
            },
            locationConfirm(value, index) {
                this.form.tabBasic.B01 = value
                this.locationShow = false
            },
            currentplantoggle(index) {
                this.$refs.currentplancheckboxes[index].toggle();
            },
            lastplantoggle(index) {
                this.$refs.lastplancheckboxes[index].toggle();
            },
            ecgToggle(index) {
                this.$refs.ecgcheckboxes[index].toggle();
            },
            toggle(index) {
                this.$refs.checkboxes[index].toggle();
            },
            saveCheck() {
                if (!this.form.tabBasic.B02) {
                    alert("请输入年龄！")
                    return false
                }
                if (!this.form.tabBasic.B04) {
                    alert("请输入体重！")
                    return false
                }
                if (!this.form.tabBasic.B07) {
                    alert("请输入身高！")
                    return false
                }
                if (!this.form.tabBasic.B05) {
                    alert("请输入BMI！")
                    return false
                }
                if (!this.form.tabBasic.B03) {
                    alert("请选择性别！")
                    return false
                }
                if (!this.form.tabBasic.B01) {
                    alert("请选择地点！")
                    return false
                }

                if (!this.form.tabBasic.B06) {
                    alert("请选择病程！")
                    return false
                }

                if (!this.form.tabDisease.D01) {
                    alert("请输入空腹血糖！")
                    return false
                }
                if (!this.form.tabDisease.D02) {
                    alert("请输入餐后血糖！")
                    return false
                }
                if (!this.form.tabDisease.D03) {
                    alert("请输入糖化血红蛋白！")
                    return false
                }
                if (this.form.tabComplication.C15.includes('急性冠脉综合征')) {
                    if (!this.form.tabComplication.C07) {
                        alert("请选择目前状态！")
                        return false
                    }
                    if (this.form.tabComplication.C07 == '急性发作') {
                        if (!this.form.tabComplication.C08) {
                            alert("请选择心电图！")
                            return false
                        }
                        if (!this.form.tabComplication.C09) {
                            alert("请选择急性期治疗方案！")
                            return false
                        }
                    }
                }
                if (this.form.tabComplication.C15.includes('高血压')) {
                    if (!this.form.tabComplication.C13) {
                        alert("请输入收缩压！")
                        return false
                    }
                    if (!this.form.tabComplication.C14) {
                        alert("请输入舒张压！")
                        return false
                    }
                }
                if (this.form.tabBasic.B06 != '新诊断或小于半年') {
                    if (this.form.treatment.T09.length < 1) {
                        alert("请选择上次治疗方案！")
                        return false
                    }
                }

                if (this.form.treatment.T05.length < 1) {
                    alert("请选择当前治疗方案！")
                    return false
                }

                if (!this.form.treatment.T06) {
                    alert("请输入目前亚莫利剂量！")
                    return false
                }

                if (!this.form.treatment.T08) {
                    alert("请选择建议亚莫利用药时间！")
                    return false
                }

                return true
            },
            save() {
                this.form.finish = false
                this.$emit('save', Object.assign({}, this.form))
                this.$nextTick(() => {
                    document.querySelector(`#cc`).scrollIntoView({
                        block: "start" // 上边框与视窗顶部平齐。默认值
                    });
                });
                this.form = {
                    finish: false,
                    callPlanId: this.scheduleId,
                    prodName: '亚莫利',
                    prodId: 'NESINA',
                    tabBasic: {
                        B02: '',
                        B04: '',
                        B07: '',
                        B05: '',
                        B03: '',
                        B01: '',
                        B06: ''
                    },
                    tabDisease: {
                        D01: '',
                        D02: '',
                        D03: '',
                    },
                    tabComplication: {
                        C15: [],
                        C07: '',
                        C09: '',
                        C08: [],
                        C14: '',
                        C13: ''
                    },
                    treatment: {
                        T09: [],
                        T05: [],
                        T06: '',
                        T08: ''
                    }
                }
                this.$emit('hide')
            },
            submit() {
                this.form.finish = this.saveCheck()
                if(this.form.finish){
                    this.$emit('save', Object.assign({}, this.form))
                    this.$emit('hide')
                }else{
                    return
                }
                this.$nextTick(() => {
                    document.querySelector(`#cc`).scrollIntoView({
                        block: "start" // 上边框与视窗顶部平齐。默认值
                    });
                });
                this.form = {
                    finish: false,
                    callPlanId: this.scheduleId,
                    prodName: '亚莫利',
                    prodId: 'NESINA',
                    tabBasic: {
                        B02: '',
                        B04: '',
                        B07: '',
                        B05: '',
                        B03: '',
                        B01: '',
                        B06: ''
                    },
                    tabDisease: {
                        D01: '',
                        D02: '',
                        D03: '',
                    },
                    tabComplication: {
                        C15: [],
                        C07: '',
                        C09: '',
                        C08: [],
                        C14: '',
                        C13: ''
                    },
                    treatment: {
                        T09: [],
                        T05: [],
                        T06: '',
                        T08: ''
                    }
                }
            }
        },
        mounted() {
        },
        watch: {
            tabActive(newval, oldval) {
                this.activeStep = newval
            },
            'form.tabComplication.C15': {
                handler(newval, oldval) {
                    if (!newval.includes('高血压')) {
                        this.form.tabComplication.C13 = ''
                        this.form.tabComplication.C14 = ''
                    }
                    if (!newval.includes('急性冠脉综合征')) {
                        this.form.tabComplication.C07 = ''
                        this.form.tabComplication.C08 = []
                        this.form.tabComplication.C09 = ''
                    }
                },
                deep: true,
                immediate: true
            },
            'form.tabComplication.C07': {
                handler(newval, oldval) {
                    if (newval == '急性发作') {
                        this.form.tabComplication.C08 = []
                        this.form.tabComplication.C09 = ''
                    }
                },
                deep: true,
                immediate: true
            }
        }
    }
</script>

<style scoped>
    .wrapper {
        padding: 20px;
    }

    .title {
        display: flex;
        flex-direction: row;
        align-items: center;
        /*margin-bottom: 10px;*/
    }

    .title_block {
        background: #ACB318;
        width: 4px;
        height: 20px;
    }

    .title_text {
        font-family: PingFangSC-Semibold;
        font-size: 16px;
        color: #333333;
        letter-spacing: 0.3px;
        text-align: justify;
        line-height: 24px;
        margin-left: 12px;
    }

    .field_title {
        font-family: PingFangSC-Regular;
        font-size: 12px;
        color: #999999;
        letter-spacing: 0.22px;
        text-align: justify;
        line-height: 16px;
    }

    .field_item {
        margin-top: 10px;
    }

    .submit {
        width: 100%;
        height: 48px;
        display: flex;
        justify-content: center;
        margin-top: 50px;
        margin-bottom: 20px;
    }

    .submit_btn {
        width: 90%;
        height: 48px;
        background: #ACB318;
        border-radius: 2px;
        border-radius: 2px;
        display: flex;
        align-items: center;
        justify-content: center;
        color: #fff;
    }
    .submit_btn2{
        width: 90%;
        height: 48px;
        background: #454592;
        border-radius: 2px;
        border-radius: 2px;
        display: flex;
        align-items: center;
        justify-content: center;
        color: #fff;
        margin: 0 auto;
    }
    .mt20 {
        margin-top: 20px;
    }

    .title_sub {
        font-family: PingFangSC-Regular;
        font-size: 14px;
        color: #454592;
        letter-spacing: 0.26px;
        text-align: justify;
        margin-top: 20px;
    }

    .van-cell {
        padding: 10px 0px !important;
        border-bottom: 1px solid #ddd;
    }
</style>